import 'package:flutter/material.dart';

import '../listView/listData.dart';

class CardViewPage1 extends StatelessWidget {
  const CardViewPage1({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Card 组件 列表'),
        ),
        body: ListView(
          children: [
            _buildCardView('汪方晨', 'Java工程师', '15217764126', '深圳'),
            _buildCardView('方晨', 'Android工程师', '15217764128', '上海'),
          ],
        ),
      ),
    );
  }

  _buildCardView(name, title, phone, address) {
    return Card(
      margin: EdgeInsets.all(10),
      elevation: 5,
      child: Column(
        children: [
          ListTile(
            title: Text(
              '$name',
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 22,
                  color: Colors.black),
            ),
            subtitle: Text(
              '$title',
              style: TextStyle(
                fontSize: 12,
              ),
            ),
          ),
          SizedBox(
            height: 5,
          ),
          Divider(
            height: 1,
          ),
          Container(
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.only(left: 15, top: 10),
            child: Text('$phone'),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            padding: EdgeInsets.only(left: 10, bottom: 10),
            alignment: Alignment.centerLeft,
            child: Text('$address'),
          )
        ],
      ),
    );
  }
}

class CardViewPage2 extends StatelessWidget {
  const CardViewPage2({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Card 图文组合 列表'),
        ),
        body: ListView(
          children: [
            _buildCardView('汪方晨', 'Java工程师',
                'https://img1.baidu.com/it/u=2916056824,1168874238&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500'),
            /*  _buildCardView('方晨', 'Android',
                'https://img9.51tietu.net/pic/2019-091018/01fowhmynz501fowhmynz5.jpg'),*/
            _buildCardView('方晨', 'Android',
                'https://img1.baidu.com/it/u=2232118840,2802419238&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500')
            //  _buildCardView('方晨', 'Android工程师', '15217764128', '上海'),
          ],
        ),
      ),
    );
  }

  _buildCardView(name, title, bgurl) {
    return Card(
      // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),

      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(10.0)),
      ),
      //对Widget截取的行为，比如这里 Clip.antiAlias 指抗锯齿
      clipBehavior: Clip.antiAlias,
      elevation: 20,
      margin: const EdgeInsets.all(10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          AspectRatio(
            aspectRatio: 16 / 9, //宽高比
            child: Image.network("$bgurl",
                width: 250.0, height: 250.0, fit: BoxFit.cover),
          ),
          ListTile(
            /*  leading: CircleAvatar(
                radius: 105,
                backgroundColor: Color(0xffFDCF09),
                child: CircleAvatar(
                  radius: 100,
                  backgroundImage: NetworkImage("$bgurl"),
                )),*/

            leading: ClipOval(
              child: Image.network(
                "$bgurl",
                fit: BoxFit.cover,
                height: 40,
                width: 40,
              ),
            ),
            title: Text(
              '$name',
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 22,
                  color: Colors.black),
            ),
            subtitle: Text(
              '$title',
              style: TextStyle(
                fontSize: 12,
              ),
            ),
          ),
        ],
      ),
      /*   child: Column(
        children: [
          AspectRatio(
            aspectRatio: 16 / 9,
            child: Image.network("https://www.itying.com/images/flutter/3.png",
                fit: BoxFit.cover),
          ),
          ListTile(
            leading: ClipOval(
              child: Image.network(
                "https://www.itying.com/images/flutter/3.png",
                fit: BoxFit.cover,
                height: 40,
                width: 40,
              ),
            ),
            title: const Text("xxxxxxxxx"),
            subtitle: const Text("xxxxxxxxx"),
          )
        ],
      ),*/
    );
  }
}

class CardViewPage3 extends StatelessWidget {
  const CardViewPage3({super.key});

  @override
  Widget build(BuildContext context) {
    List<Widget> _createView() {
      var tempList = listData.map((value) {
        return _buildCardView(
            value['title'], value['author'], value['imageUrl']);
      });
      return tempList.toList();
    }

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Card 图文组合 列表'),
        ),
        body: ListView(
          children: _createView(),
        ),
      ),
    );
  }

  Widget _buildCardView(name, title, bgurl) {
    return Card(
      // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),

      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(10.0)),
      ),
      //对Widget截取的行为，比如这里 Clip.antiAlias 指抗锯齿
      clipBehavior: Clip.antiAlias,
      elevation: 20,
      margin: const EdgeInsets.all(10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          AspectRatio(
            aspectRatio: 16 / 9, //宽高比
            child: Image.network("$bgurl",
                width: 250.0, height: 250.0, fit: BoxFit.cover),
          ),
          ListTile(
            /*  leading: CircleAvatar(
                radius: 105,
                backgroundColor: Color(0xffFDCF09),
                child: CircleAvatar(
                  radius: 100,
                  backgroundImage: NetworkImage("$bgurl"),
                )),*/

            leading: ClipOval(
              child: Image.network(
                "$bgurl",
                fit: BoxFit.cover,
                height: 40,
                width: 40,
              ),
            ),
            title: Text(
              '$name',
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 22,
                  color: Colors.black),
            ),
            subtitle: Text(
              '$title',
              style: TextStyle(
                fontSize: 12,
              ),
            ),
          ),
        ],
      ),
      /*   child: Column(
        children: [
          AspectRatio(
            aspectRatio: 16 / 9,
            child: Image.network("https://www.itying.com/images/flutter/3.png",
                fit: BoxFit.cover),
          ),
          ListTile(
            leading: ClipOval(
              child: Image.network(
                "https://www.itying.com/images/flutter/3.png",
                fit: BoxFit.cover,
                height: 40,
                width: 40,
              ),
            ),
            title: const Text("xxxxxxxxx"),
            subtitle: const Text("xxxxxxxxx"),
          )
        ],
      ),*/
    );
  }
}
